package JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Text_login {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String name = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();
        Connection connection=null;
        Statement statement = null;
        ResultSet resultSet=null;
        //获取数据库连接对象
        try {
            connection = JDBCUtil.getConnection();
            statement = connection.createStatement();
            /*
            * 使用statement 执行 sql语句存在 sql 注入风险
            * */
            String sql = "select * from master where username='" + name + "' and userpassword='" + password + "'";
             resultSet = statement.executeQuery(sql);
             if (resultSet.next()){
                 System.out.println("登入成功......");
             }else {
                 System.out.println("登入失败~~~~~");
             }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {

               JDBCUtil.close(resultSet, statement, connection);

        }


    }
}
